﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using com.loto.Common.DBUtility;
using com.loto.Common.Model;

namespace com.huigo.Framework.SqlServerDal
{
    public partial class PolicyInfoTravel
    {
        public static long AddPolicy(Model.PolicyInfoTravel policyInfoTravel, SqlTransaction trans)
        {
            string sql = "insert into [HG_POLICY_INFO_TRAVEL]({0}) values({1})";
            List<string> f = new List<string>();
            List<string> v = new List<string>();
            List<SqlParameter> paraList = new List<SqlParameter>();
            SqlParameter para;

            if (!policyInfoTravel.PolicyId.Equals(long.MinValue))
            {
                f.Add(" POLICY_ID");
                v.Add(" @POLICY_ID");
                para = new SqlParameter("@POLICY_ID", SqlDbType.BigInt, 8);
                para.Value = policyInfoTravel.PolicyId;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyOrderFid.Equals(long.MinValue))
            {
                f.Add(" POLICY_ORDER_FID");
                v.Add(" @POLICY_ORDER_FID");
                para = new SqlParameter("@POLICY_ORDER_FID", SqlDbType.BigInt, 8);
                para.Value = policyInfoTravel.PolicyOrderFid;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyCustFid.Equals(long.MinValue))
            {
                f.Add(" POLICY_CUST_FID");
                v.Add(" @POLICY_CUST_FID");
                para = new SqlParameter("@POLICY_CUST_FID", SqlDbType.BigInt, 8);
                para.Value = policyInfoTravel.PolicyCustFid;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyHolderName.Equals(string.Empty))
            {
                f.Add(" POLICY_HOLDER_NAME");
                v.Add(" @POLICY_HOLDER_NAME");
                para = new SqlParameter("@POLICY_HOLDER_NAME", SqlDbType.NVarChar, 20);
                para.Value = policyInfoTravel.PolicyHolderName;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyHolderCredentialType.Equals(string.Empty))
            {
                f.Add(" POLICY_HOLDER_CREDENTIAL_TYPE");
                v.Add(" @POLICY_HOLDER_CREDENTIAL_TYPE");
                para = new SqlParameter("@POLICY_HOLDER_CREDENTIAL_TYPE", SqlDbType.NVarChar, 10);
                para.Value = policyInfoTravel.PolicyHolderCredentialType;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyHolderCredentialNo.Equals(string.Empty))
            {
                f.Add(" POLICY_HOLDER_CREDENTIAL_NO");
                v.Add(" @POLICY_HOLDER_CREDENTIAL_NO");
                para = new SqlParameter("@POLICY_HOLDER_CREDENTIAL_NO", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyHolderCredentialNo;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyHolderBirth.Equals(DateTime.MinValue))
            {
                f.Add(" POLICY_HOLDER_BIRTH");
                v.Add(" @POLICY_HOLDER_BIRTH");
                para = new SqlParameter("@POLICY_HOLDER_BIRTH", SqlDbType.Date, 3);
                para.Value = policyInfoTravel.PolicyHolderBirth;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyHolderGender.Equals(string.Empty))
            {
                f.Add(" POLICY_HOLDER_GENDER");
                v.Add(" @POLICY_HOLDER_GENDER");
                para = new SqlParameter("@POLICY_HOLDER_GENDER", SqlDbType.Char, 2);
                para.Value = policyInfoTravel.PolicyHolderGender;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredName.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_NAME");
                v.Add(" @POLICY_INSURED_NAME");
                para = new SqlParameter("@POLICY_INSURED_NAME", SqlDbType.NVarChar, 20);
                para.Value = policyInfoTravel.PolicyInsuredName;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredCredentialType.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_CREDENTIAL_TYPE");
                v.Add(" @POLICY_INSURED_CREDENTIAL_TYPE");
                para = new SqlParameter("@POLICY_INSURED_CREDENTIAL_TYPE", SqlDbType.NVarChar, 10);
                para.Value = policyInfoTravel.PolicyInsuredCredentialType;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredCredentialNo.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_CREDENTIAL_NO");
                v.Add(" @POLICY_INSURED_CREDENTIAL_NO");
                para = new SqlParameter("@POLICY_INSURED_CREDENTIAL_NO", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyInsuredCredentialNo;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredBirth.Equals(DateTime.MinValue))
            {
                f.Add(" POLICY_INSURED_BIRTH");
                v.Add(" @POLICY_INSURED_BIRTH");
                para = new SqlParameter("@POLICY_INSURED_BIRTH", SqlDbType.Date, 3);
                para.Value = policyInfoTravel.PolicyInsuredBirth;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredGender.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_GENDER");
                v.Add(" @POLICY_INSURED_GENDER");
                para = new SqlParameter("@POLICY_INSURED_GENDER", SqlDbType.Char, 2);
                para.Value = policyInfoTravel.PolicyInsuredGender;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyTravelLine.Equals(string.Empty))
            {
                f.Add(" POLICY_TRAVEL_LINE");
                v.Add(" @POLICY_TRAVEL_LINE");
                para = new SqlParameter("@POLICY_TRAVEL_LINE", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyTravelLine;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyFromPeriod.Equals(DateTime.MinValue))
            {
                f.Add(" POLICY_FROM_PERIOD");
                v.Add(" @POLICY_FROM_PERIOD");
                para = new SqlParameter("@POLICY_FROM_PERIOD", SqlDbType.DateTime, 8);
                para.Value = policyInfoTravel.PolicyFromPeriod;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredTel.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_TEL");
                v.Add(" @POLICY_INSURED_TEL");
                para = new SqlParameter("@POLICY_INSURED_TEL", SqlDbType.NVarChar, 20);
                para.Value = policyInfoTravel.PolicyInsuredTel;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyInsuredEmail.Equals(string.Empty))
            {
                f.Add(" POLICY_INSURED_EMAIL");
                v.Add(" @POLICY_INSURED_EMAIL");
                para = new SqlParameter("@POLICY_INSURED_EMAIL", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyInsuredEmail;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyUnitPrice.Equals(decimal.MinValue))
            {
                f.Add(" POLICY_UNIT_PRICE");
                v.Add(" @POLICY_UNIT_PRICE");
                para = new SqlParameter("@POLICY_UNIT_PRICE", SqlDbType.Money, 8);
                para.Value = policyInfoTravel.PolicyUnitPrice;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyCount.Equals(int.MinValue))
            {
                f.Add(" POLICY_COUNT");
                v.Add(" @POLICY_COUNT");
                para = new SqlParameter("@POLICY_COUNT", SqlDbType.Int, 4);
                para.Value = policyInfoTravel.PolicyCount;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyStatus.Equals(int.MinValue))
            {
                f.Add(" POLICY_STATUS");
                v.Add(" @POLICY_STATUS");
                para = new SqlParameter("@POLICY_STATUS", SqlDbType.Int, 4);
                para.Value = policyInfoTravel.PolicyStatus;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyFeeStatus.Equals(int.MinValue))
            {
                f.Add(" POLICY_FEE_STATUS");
                v.Add(" @POLICY_FEE_STATUS");
                para = new SqlParameter("@POLICY_FEE_STATUS", SqlDbType.Int, 4);
                para.Value = policyInfoTravel.PolicyFeeStatus;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyOutOrderNo.Equals(string.Empty))
            {
                f.Add(" POLICY_OUT_ORDER_NO");
                v.Add(" @POLICY_OUT_ORDER_NO");
                para = new SqlParameter("@POLICY_OUT_ORDER_NO", SqlDbType.NVarChar, 14);
                para.Value = policyInfoTravel.PolicyOutOrderNo;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyTradeOrderNo.Equals(string.Empty))
            {
                f.Add(" POLICY_TRADE_ORDER_NO");
                v.Add(" @POLICY_TRADE_ORDER_NO");
                para = new SqlParameter("@POLICY_TRADE_ORDER_NO", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyTradeOrderNo;
                paraList.Add(para);
            }
            if (!policyInfoTravel.PolicyNo.Equals(string.Empty))
            {
                f.Add(" POLICY_NO");
                v.Add(" @POLICY_NO");
                para = new SqlParameter("@POLICY_NO", SqlDbType.NVarChar, 50);
                para.Value = policyInfoTravel.PolicyNo;
                paraList.Add(para);
            }

            SqlCommand cmd = new SqlCommand();
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = string.Format(sql, string.Join(",", f.ToArray()), string.Join(",", v.ToArray()));
            cmd.Parameters.AddRange(paraList.ToArray());
            try
            {
                return Convert.ToInt64(SqlHelper.ExecuteScalar(SqlHelper.MainSQLConnString, cmd, trans));
            }
            catch (Exception exce)
            {
                throw exce;
            }
        }

    }
}
